﻿<?php

/**
 * SDK基类  By Weiping @imShadow
 */
 
 class ApiObject {
 	
 	protected $accesskey; //服务商店 AccessKey | SAE应用用户为 应用  AceessKey
 	protected $secretkey; //服务商店 SecretKey | SAE应用用户为 应用  SecretKey
 	
 	function __construct($accesskey, $secretkey) {
	
		$this->accesskey = $accesskey;
		$this->secretkey = $secretkey;
	}
	
	/**
	 * 解析API返回结果
	 * @params String $string  返回结果字符串
	 * @params String type	 返回结果格式 ( json / xml )
	 * @return Mix(Object/Array) 
	 */
	public function decode( $string,  $type='json' ) {
	 
		$fun = "{$type}_decode"; //json_decode / xml_decode;
		return $this->$fun( $string );
	}
	
	/**
	 * 检测变量是否为 ApiBus错误对象 
	 * @params Mix $object 待检测变量
	 * @return Bool 错误对象返回True 其他返回 false
	 */
	public function isError(&$object ) {
		if ( is_object($object) && isset($object->ApiBusError) ) {
			return true;
		}
		return false;
	}
		
	public function json_decode( $string ) {				
		return json_decode( $string,true );
	}
	
	public function json_encode( $object ) {
	
		return json_encode( $object );
	}
	
	public function xml_encode() {
	
	}
	public function xml_decode()  { 
		return simplexml_load_string($string);
	}
 
 }